<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/res/commons/taglib.jsp" %>
<!DOCTYPE html>
<html>
  
<head>
    <meta charset="UTF-8">
    <title>æ¬¢è¿é¡µé¢-L-admin1.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="shortcut icon" href="${path}/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="${path}/res/css/font.css">
    <link rel="stylesheet" href="${path}/res/css/xadmin.css">
    <link rel="stylesheet" href="${path}/res/css/imageupload.css">
   	<link rel="stylesheet" href="${path}/res/kindeditor/themes/default/default.css">
   	<link rel="stylesheet" href="${path}/res/css/selectcolor.css">
	<script src="${path}/res/js/selectcolor.min.js"></script>
	<script src="${path}/res/js/jquery.min.js"></script>
	<script src="${path}/res/kindeditor/kindeditor-all-min.js"></script>
	<script src="${path}/res/kindeditor/lang/js/zh-CN.js"></script>
    <script src="https://libs.baidu.com/jquery/1.11.3/jquery.min.js"></script>
    <script type="text/javascript" src="${path}/res/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="${path}/res/js/xadmin.js" charset="utf-8"></script>
    
    <script type="text/javascript" src="${path}/res/js/product.js" charset="utf-8"></script>
    
	<script>
		layui.use('laydate', function(){
	        var laydate = layui.laydate;
	        //执行一个laydate实例
	        laydate.render({
	          elem: '#proEventEndTime' //指定元素
	        });
      	});
		var editor;
		//编辑器
	    KindEditor.ready(function (K) {
        editor = K.create('#proDesc', {
 	            filePostName: "uploadFile",
 	            uploadJson: '${path}/imageupload/upload.jhtml?type=desc',
 	            resizeType: 1,
 	            allowPreviewEmoticons: true,
 	            allowImageUpload: true,
 	        });
 	    });
		
		new SelectColor({
			elem: "#proColor",
			range: ",",
		});
	
	
    </script>
</head>
<body>
	<div class="x-body">
		<div class="layui-form-item">
			<label for="username" class="layui-form-label"><span class="x-red">*</span>Banner图</label>
			    <div id="Pic_pass">
			        <div class="picDiv" >
			            <div class="addImages">
			            
			                <input type="file" class="file" id="fileInput" multiple="multiple" accept="image/png, image/jpeg, image/gif, image/jpg" >
			            
			                <div class="text-detail">
			                    <span>+</span>
			                    <p style="color: red">注：每张照片大写不可超过4M，最多可以传十张</p>
			                </div>
			            </div>
			        </div>
			    </div>
			    <div class="msg" style="display: none;"></div>
         	</div>
				
			<div class="layui-form-item" style="width: 62%;">
				<label for="username" class="layui-form-label">
					<span class="x-red">*</span>商品标题
				</label>
              	<div class="layui-input-block">
              		<input type="text" id="proTitle" name="proTitle" required lay-verify="required" autocomplete="off" class="layui-input" placeholder="商品详情页标题">
              	</div>
          	</div>
			<div class="layui-form-item" style="width: 62%;">
				<label for="username" class="layui-form-label">
					<span class="x-red">*</span>按钮描述
				</label>
              	<div class="layui-input-block">
              		<input type="text" id="bannerDesc" name="bannerDesc" required lay-verify="required" autocomplete="off" class="layui-input" value="验货满意后付款">
              	</div>
          	</div>
			
			<div class="layui-form-item">
	            <div class="layui-inline">
					<label class="layui-form-label">
						<span class="x-red">*</span>商品原价
					</label>
	              	<div class="layui-input-inline" style="width: 200px;">
	                	<input type="text" id="proPrice" name="proPrice" placeholder="￥0.00" autocomplete="off" class="layui-input">
	              	</div>
	              	<div class="layui-form-mid">
		              	<span class="x-red">*</span>
		              	商品售价
	              	</div>
	              	<div class="layui-input-inline" style="width: 200px;">
	                	<input type="text" id="proDiscountPrice" name="proDiscountPrice" placeholder="￥0.00" autocomplete="off" class="layui-input">
	              	</div>
				</div>
			</div>
			<div class="layui-form-item">
	            <div class="layui-inline">
	            	<label class="layui-form-label">已售数量</label>
	              	<div class="layui-input-inline" style="width: 200px;">
	                	<input type="text" id="proSellNum" name="proSellNum" placeholder="999" autocomplete="off" class="layui-input">
	              	</div>
				</div>
			</div>
			
			<div class="layui-form-item" style="width: 62%;">
				<label class="layui-form-label">商品颜色</label>
              	<div class="layui-input-block">
              		<input type="text" id="proColor" name="proColor" required lay-verify="required" autocomplete="off" class="layui-input" placeholder="请选择商品颜色">
              	</div>
          	</div>
          	
          	<div class="layui-form-item" id="sizehtml">
	            <div class="layui-inline">
					<label class="layui-form-label">商品原价</label>
	              	<div class="layui-input-inline" style="width: 100px;">
	                	<input type="text" id="proSize" name="proSize" placeholder="尺寸大小" autocomplete="off" class="layui-input">
	              	</div>
	              	<div class="layui-form-mid">-</div>
	              	<div class="layui-input-inline" style="width: 200px;">
	                	<input type="text" id="proSizeDesc" name="proSizeDesc" placeholder="尺寸描述" autocomplete="off" class="layui-input">
	              	</div>
	                <button class="layui-btn layui-btn-primary layui-btn-sm" onclick="addSizeHtml()"><i class="layui-icon"></i></button>
					<br>
				</div> 
	            <div class="layui-inline" id="sizehtml2">
	            	<label class="layui-form-label"></label>
	              	<div class="layui-input-inline" style="width: 100px;">
	                	<input type="text" id="proSize" name="proSize" placeholder="XXL" autocomplete="off" class="layui-input">
	              	</div>
	              	<div class="layui-form-mid">-</div>
	              	<div class="layui-input-inline" style="width: 200px;">
	                	<input type="text" id="proPriceDesc" name="proSizeDesc" placeholder="XXL/建议体重100-130斤穿" autocomplete="off" class="layui-input">
	              	</div>
	              	<button class="layui-btn layui-btn-danger layui-btn-sm" onclick="deleteSizeHtml(2)"><i class="layui-icon"></i></button>
					<br>
				</div>
	            <div class="layui-inline" id="sizehtml3">
	            	<label class="layui-form-label"></label>
	              	<div class="layui-input-inline" style="width: 100px;">
	                	<input type="text" id="proSize" name="proSize" placeholder="39" autocomplete="off" class="layui-input">
	              	</div>
	              	<div class="layui-form-mid">-</div>
	              	<div class="layui-input-inline" style="width: 200px;">
	                	<input type="text" id="proSizeDesc" name="proPriceDesc" placeholder="39码皮鞋" autocomplete="off" class="layui-input">
	              	</div>
	              	<button class="layui-btn layui-btn-danger layui-btn-sm" onclick="deleteSizeHtml(3)"><i class="layui-icon"></i></button>
				</div>
			</div>
          <div class="layui-form-item">
              <label for="username" class="layui-form-label">
                  结束日期
              </label>
              <div class="layui-input-inline">
                  <input class="layui-input" placeholder="" name="proEventEndTime" id="proEventEndTime">
              </div>
          </div>
          <div class="layui-form-item layui-form-text">
              <label for="desc" class="layui-form-label">
                  <span class="x-red">*</span>描述
              </label>
              <div class="layui-input-block">
                  <textarea name="proDesc" id="proDesc" style="height:450px;" class="layui-textarea"></textarea>
              </div>
          </div>
          <div class="layui-form-item">
              <label for="L_repass" class="layui-form-label"></label>
              <button   class="layui-btn" lay-filter="add" lay-submit="" onclick="addSubmit()">添加</button>
          </div>
      </form>
    </div>

<script>
	new SelectColor({
		elem: "#proColor",
		range: ","
	});
	//选中图片的参数
	var layer = layui.laydate;
	//图片上传预览功能
	var userAgent = navigator.userAgent; //用于判断浏览器类型//图片上传预览功能
	$('#fileInput').change(function() {
		var fileList = $('#fileInput')[0].files;
		for(var i = 0; i < fileList.length; i++) {
			var formData = new FormData();
            formData.append('file', fileList[i]);
			$.ajax({
			    url: '${path}/imageupload/upload.jhtml?type=banner',
			    type: 'POST',
			    cache: false, //上传文件不需要缓存
			    data: formData,
			    processData: false, // 告诉jQuery不要去处理发送的数据
			    contentType: false, // 告诉jQuery不要去设置Content-Type请求头
			    success: function (data) {
			    	var rs = eval("("+data+")");
			    	var picDiv = $(".picDiv");
			    	var picHtml = '<div class="imageDiv" id="div'+rs.filename+'"> <img id="img'+rs.filename+'" name="banner" />';
			    	picHtml+='<div class="cover"><i class="delbtn" onclick="deleteFile(';
			    	picHtml+="'"+rs.filename+"'";
			    	picHtml+=')" >删除</i></div>';
			    	picHtml+='</div>';
			        picDiv.prepend(picHtml);
			        var imgObjPreview = document.getElementById("img" + rs.filename);
		            imgObjPreview.style.display = 'block';
		            imgObjPreview.style.width = '160px';
		            imgObjPreview.style.height = '130px';
                    imgObjPreview.src = "${path}"+rs.url;
			    },
			    error: function (data) {
			        layer.msg("上传失败",{icon:1,time:1000});
			    }
			}); 
		}
	});
	// 删除文件
	function deleteFile(fileName){
		$.ajax({
			url:"${path}/imageupload/deleteFile.jhtml",
		  	dataType:"json", 
		  	async:true,
		  	data:{
		  		"fileName":fileName,
		  		"type":'banner'
		  	},
		  	type:"post",
			success:function(date){
				if(date){
			 		document.getElementById("div" + fileName).remove();
			 		  bannerImage.set(fileName,null);
				}
			},
			error:function(){
			    layer.msg("服务器异常，请稍后再试",{icon:1,time:1000});
			}
		});
	}
	// 提交
	function addSubmit(){
		var img =  new Array(); 	//图片保存 必填
		var imgarr = $("img[name='banner']");
		if(imgarr.length==0){
			layer.msg("请选择图片",{icon:2,time:1000});
			return;
		}else{
			imgarr.each(function() {
				img.push($(this).attr("src"));
			});
		}
		var proTitle = $("#proTitle").val();
		if(proTitle.length==0){
			layer.msg("请输入商品标题",{icon:2,time:1000});
			return;
		}
		var proPrice = $("#proPrice").val();
		if(proPrice.length==0){
			layer.msg("请输入商品原价格",{icon:2,time:1000});
			return;
		}
		var proDiscountPrice = $("#proDiscountPrice").val();
		if(proDiscountPrice.length==0){
			layer.msg("请输入商品售价",{icon:2,time:1000});
			return;
		}
		var proSellNum = $("#proSellNum").val();
		var proColor = $("#proColor").val();
		var bannerDesc = $("#bannerDesc").val();
		
		var sizeValueArr =  new Array(); 	//大小保存
		var sizeDescArr =  new Array(); 	//大小描述保存
		
		var size = $("input[name='proSize']").val();
		var sizeDesc = $("input[name='proSizeDesc']").val();
		if(size.length>0){
			for(var i=0;i<size.length;i++){
				sizeValueArr.push(size[i]);
				sizeDescArr.push(sizeDesc[i]);
			}
		}
		var proEventEndTime = $("#proEventEndTime").val();
		var prodesc = editor.html();
		if(prodesc.length==0){
			layer.msg("请编辑商品详情",{icon:2,time:1000});
			return;
		}
		$.ajax({
			url:"${path}/product/productadd.jhtml",
		  	dataType:"json", 
		  	async:true,
		  	data:{
		  		"banner":img.toString(),
		  		"proTitle":proTitle,
		  		"bannerDesc":bannerDesc,
		  		"proPrice":proPrice,
		  		"proDiscountPrice":proDiscountPrice,
		  		"proSellNum":proSellNum,
		  		"proColor":proColor,
		  		"proSize":sizeValueArr.toString(),
		  		"proSizeDesc":sizeDescArr.toString(),
		  		"proEventEndTime":proEventEndTime,
		  		"proDesc":prodesc
		  		},
		  	type:"post",
			success:function(date){
				
			},
			error:function(){
			    alert("服务器异常，请稍后再试");
			}
		});
	}
</script>
    
</body>
</html>